﻿// 1.1.9.06.  Write a method that returns the position of the first occurrence of an element from an array,
// such that it is greater than its two neighbours simultaneously. Otherwise the result must be -1.
// - Use the method from the previous exercise.

using System;

class FirstGreaterThanTwoNeighbours
{
    public static bool IsItGreatThanItsNeighbours(byte position, int[] arry)
    {
        bool isGreater = arry[position] > arry[position - 1] && arry[position] > arry[position + 1];
        return isGreater;
    }
    public static int FirstElementGreaterThanitsNeighbours(int[] arry)
    {
        for (byte i = 1; i < arry.GetLength(0) - 1; i++)
        {
            if (IsItGreatThanItsNeighbours(i, arry) == true)
            {
                return i;
                // return Array.IndexOf(arry, arry[i]);
            }
        }
        return -1;
    }
    static void Main()
    {
        int[] arr = { 1, 77, 1, 5 };
        Console.WriteLine(FirstElementGreaterThanitsNeighbours(arr));
    }
}
